Page({
  goLogin() {
    wx.navigateTo({
      url: '/pages/login/index',
    })
  },
  onShow(){
    //页面显示获取最新的用户数据
    this.getUserInfo()
  },
  //获取用户信息
  async getUserInfo(){
      const {code,data} = await wx.http.get('/userInfo')
      if(code != 10000) return wx.utils.toast('获取信息失败','fail')
      this.setData({
          nickName:data.nickName,
          userAvatar:data.avatar
        })
  },

  // 测试存和删token
  saveToken(){
    wx.setStorageSync('token', 'asdasdasdafasf')
    wx.utils.toast('存储成功','success')
  },
  delToken(){
    wx.removeStorageSync('token')
    const app = getApp()
    app.token = ''
    wx.utils.toast('删除成功','success')
  },
  //测试刷新token的接口
  async testRefreshToken(){
    try{
      const res = await wx.http.get('/room')
      console.log(res)
    }catch(e){
      console.log('获取房屋列表失败');
    }
  }
})
